// executors/executor_GitHubLimitedCollector.js (放在 executors 目录下)

/**
 * 演示有限次数执行：模拟数据采集或自动翻页。
 */
export async function execute(rule) {
    const element = document.body;
    const currentCount = parseInt(element.dataset.collectCount || 0) + 1;
    element.dataset.collectCount = currentCount;

    const maxRuns = rule.maxExecutions;

    console.log(`[Limited Collector] Rule: ${rule.name} | Run: ${currentCount} / ${maxRuns}`);

    // 模拟数据采集过程
    const searchInput = document.querySelector('input[name="q"]');
    if (searchInput) {
        searchInput.value = `run-${currentCount} data collection...`;
        searchInput.style.border = '3px solid blue';
    }

    // 模拟执行耗时操作 (例如：等待 API 响应)
    await new Promise(resolve => setTimeout(resolve, 500));

    if (currentCount < maxRuns) {
        console.log(`[Limited Collector] Next execution scheduled in ${rule.intervalMs / 1000} seconds.`);
    } else {
        console.log(`[Limited Collector] FINAL RUN COMPLETE! Stopping data collection task.`);
    }
}